package www.dianbaozu.com.ui.server

import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lihang.ShadowLayout
import com.netease.nim.uikit.api.NIMHelper
import www.dianbaozu.com.R
import www.wen.com.common.lib.data.entities.ServerSelfListEntity
import www.wen.com.common.lib.extension.glide.setImageUrl
import www.wen.com.common.lib.extension.imgUrl
import www.wen.com.common.lib.extension.unread
import www.wen.com.common.lib.view.rcimageView.RCImageView

/**
 * @author WEN
 * @Description:
 * @date 2021/9/17 1:41
 */
class ServerAdapter : BaseQuickAdapter<ServerSelfListEntity.Content, BaseViewHolder>(R.layout.item_server_avatar), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: ServerSelfListEntity.Content) {

        holder.setVisible(R.id.ivSelected,item.isSelected)

        if(item.isSelected){
            holder.getView<RCImageView>(R.id.ivAvatar).isRoundAsCircle = false
            holder.getView<RCImageView>(R.id.ivAvatar).setRadius(10)
        }else{
            holder.getView<RCImageView>(R.id.ivAvatar).isRoundAsCircle = true
        }

        item.unreadCount = 0
        item.teamIds?.forEach {
            item.unreadCount += NIMHelper.teamUnreadCountMap[it]?:0
        }
        holder.setText(R.id.tvUnreadMessage,item.unreadCount.unread())
        holder.getView<ShadowLayout>(R.id.slUnreadMessage).isVisible = item.unreadCount > 0

        setImageUrl(holder.getView(R.id.ivAvatar), item.serverLogo.imgUrl())
    }

}